package org.timemanager.view;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.AutoCompleteTextView;

/**
 * when obtaining input focus,
 * then display drop down list to show the candidate list for quick choose,
 * and the user also can add a new item.
 */
public class MyAutoCompleteTextView extends AutoCompleteTextView {

	public MyAutoCompleteTextView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public MyAutoCompleteTextView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public MyAutoCompleteTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean enoughToFilter() {
		// TODO Auto-generated method stub
		/*
		 * judge whether to display the drop down list,
		 * now show it at once.
		 */
		return true;
	}

	@Override
	protected void onFocusChanged(boolean focused, int direction,
			Rect previouslyFocusedRect) {
		super.onFocusChanged(focused, direction, previouslyFocusedRect);
		if(focused){
			/*
			 * only by using this sentence there won't show drop down list
			 * again when it removes focus first and obtain focus again
			 */
			performFiltering(getText(), KeyEvent.KEYCODE_UNKNOWN);
			/*
			 * this makes drop down list visible when its has focus again
			 */
			showDropDown();
		}
	}

}
